package com.svms.service.mapper;

import java.util.Date;

import com.svms.model.SvmsMovement;
import com.svms.service.factory.SvmsServiceFactory;
import com.svms.service.vo.MovementVO;
import com.svms.service.vo.VehicleVO;

/**
 * @author om39a
 * 
 */
public final class MovementMapper {

	private MovementMapper() {

	}

	public static MovementVO dmlToService(SvmsMovement svmsMovement) {

		MovementVO movementVO = new MovementVO();
		VehicleVO vehicle = new VehicleVO();
		
		vehicle.setVehicleId(String.valueOf(svmsMovement.getVehicleId()));
		
		movementVO.setVehicleVO(SvmsServiceFactory.getInstance().getVehicle()
				.getVehicle(vehicle));
		movementVO.setMovementId(String.valueOf(svmsMovement.getMovememtId()));
		movementVO.setDistanceTraveled(String.valueOf(svmsMovement
				.getTripDistance()));
		movementVO.setStartDate(svmsMovement.getStartDate());
		movementVO.setEndDate(svmsMovement.getEndDate());
		movementVO.setStartPlace(svmsMovement.getStartPlace());
		movementVO.setEndPlace(svmsMovement.getEndPlace());
		movementVO.setStuffingPlace(svmsMovement.getStartPlace());
		return movementVO;
	}

	public static SvmsMovement serviceToDml(MovementVO movementVO) {

		SvmsMovement svmsMovement = new SvmsMovement();

		svmsMovement.setVehicleId(Long.valueOf(movementVO.getVehicleVO()
				.getVehicleId()));
		svmsMovement.setMovememtId(Integer.valueOf(movementVO.getMovementId()));
		svmsMovement.setStartDate(movementVO.getStartDate());
		svmsMovement.setEndDate(movementVO.getEndDate());
		svmsMovement.setStartPlace(movementVO.getStartPlace());
		svmsMovement.setEndPlace(movementVO.getEndPlace());
		svmsMovement.setStuffingPlace(movementVO.getStuffingPlace());
		svmsMovement.setTripDistance(Integer.valueOf(movementVO
				.getDistanceTraveled()));
		svmsMovement.setUpdateBy("admin");
		svmsMovement.setUpdatedTime(new Date());
		return svmsMovement;
	}
}
